home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENTRY.SWG / 0010_FergSoft! ReadLn.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  8KB  |  187 lines

  1. {
  2.         Ok, y'all, here's a function I've been working on for a while, and
  3.         I thought I'd post it for everybody.  It's a modified ReadLn
  4.         routine, and while there's no guarantees, <What's new?>, I _think_
  5.         it's bug free. <Crossing fingers>  If y'all want to use it, go
  6.         ahead, but I would like some credit, 'cuz it took me a while.  Just
  7.         credit FergSoft!, Artificial Reality, Whizard, or Justin Ferguson.
  8.         It's fairly well commented, but just throw any questions you may
  9.         have my way...
  10.  
  11. --- Cut Here ---
  12. }
  13.  
  14. unit FSRead;
  15.  
  16. {------------------------------------------------------------------------}
  17. {
  18.       FergSoft! ReadLn Routine:
  19.  
  20.                 By Justin Ferguson of FergSoft!,
  21.                 a. k. a. Whizard of Artificial Reality.
  22.  
  23.       FSReadLn reads a string of specified length, at specified
  24.       location, in specified colors, terminated by TAB or Enter.
  25.  
  26.       Feel free to use this little unit anywhere y'all want, just give
  27.       credit for it.
  28.  
  29.  
  30.                                 Thanx, Whizard
  31.  
  32.                                                                          }
  33. {------------------------------------------------------------------------}
  34.  
  35. INTERFACE
  36.  
  37. uses Crt;
  38.  
  39. Function FSReadLn (X,                                         {X Location}
  40.                    Y,                                         {Y Location}
  41.                    FC,                                  {Foreground Color}
  42.                    BC,                                  {Background Color}
  43.                    StrLength : Byte;  {Length of string to input.  Will be
  44.                                        padded with spaces (#32).         }
  45.  
  46.                    Default : String       {Default string, leave '' for no
  47.                                            default                       }
  48.                     ) : String;
  49.  
  50. {------------------------------------------------------------------------}
  51.  
  52. IMPLEMENTATION
  53.  
  54. Function FSReadLn (X, Y, FC, BC, StrLength : Byte; Default : String)
  55.                                                                  : String;
  56.  
  57. var Temp : String;                      {Temporary string}
  58.     Location : Byte;                    {Current location in string}
  59.     QuitFlag, InsFlag : Boolean;        {Flags}
  60.     Ch : Char;                          {Current Character}
  61.     Z : Integer;                        {Temp variable}
  62.     Cursor : Word absolute $0040:$0060; {Cursor format}
  63.  
  64. begin
  65.      QuitFlag := False;
  66.      InsFlag := True;
  67.  
  68.      For Z := 1 to 255 do               {Clear string to spaces}
  69.          Temp[Z] := ' ';
  70.  
  71.      For Z := 1 to Length(Default) do   {Set to default string}
  72.          Temp[Z] := Default[Z];
  73.  
  74.      Temp[0] := Chr(StrLength);         {Set length of string}
  75.      Location := 1;
  76.      Ch := #1;
  77.      Temp[StrLength + 1] := #32;
  78.      GotoXY(X, Y);
  79.      Write(Temp);
  80.  
  81.      Repeat
  82.            Case Ch of
  83.                 #32..#127 : begin                    {Regular ASCII}
  84.                               If InsFlag = False then
  85.                                 begin
  86.                                   If Location <= StrLength then
  87.                                     begin
  88.                                       Location := Location + 1;
  89.                                       Temp[Location] := Ch;
  90.                                     end;
  91.                                   end
  92.                                 else
  93.                                   begin
  94.                                     If Location <= StrLength then
  95.                                       begin
  96.                                         For Z := StrLength - 1 downto
  97.                                                            Location do
  98.                                           Temp[Z + 1] := Temp[Z];
  99.  
  100.                                           Temp[Location] := Ch;
  101.                                           Location := Location + 1;
  102.                                       end;
  103.                                   end;
  104.                             end;
  105.                 #27       : begin                              {ESC}
  106.                               For Z := 1 to StrLength do
  107.                                 Temp[Z] := ' ';
  108.                               Location := 1;
  109.                             end;
  110.                 #9, #13   : QuitFlag := True;           {Tab}{Enter}
  111.                 #8        : begin                        {Backspace}
  112.                               If Location > 1 then
  113.                                 begin
  114.                                   Location := Location - 1;
  115.                                     For Z := Location to StrLength do
  116.                                       begin
  117.                                         Temp[Z] := Temp[Z + 1];
  118.                                       end;
  119.                                 end;
  120.                             end;
  121.  
  122.                 #0        : begin     {Extended keys... }
  123.                               Ch := ReadKey;
  124.                               Case Ch of
  125.  
  126.                                 #75 : begin             {Left arrow}
  127.                                         If Location > 1 then
  128.                                           Location := Location - 1;
  129.                                       end;
  130.                                 #77 : begin            {Right arrow}
  131.                                         If Location < (StrLength - 1) then
  132.                                           Location := Location + 1;
  133.                                       end;
  134.                                 #71 : Location := 1;          {Home}
  135.                                 #79 : Location := StrLength;   {End}
  136.                                 #82 : If InsFlag = True     {Insert}
  137.                                         then
  138.                                           begin
  139.                                             InsFlag := False;
  140.                                             asm
  141.                                                MOV AH, $01
  142.                                                MOV CX, $0F
  143.                                                INT $10
  144.                                             end;
  145.                                           end
  146.                                         else
  147.                                           begin
  148.                                             InsFlag := True;
  149.                                             asm
  150.                                                MOV AH, $01
  151.                                                MOV CL, $07
  152.                                                MOV CH, $06
  153.                                                INT $10
  154.                                             end;
  155.                                           end;
  156.                                                             {Delete}
  157.                                 #83 : For Z := Location to StrLength do
  158.                                         Temp[Z] := Temp[Z + 1];
  159.                               end;
  160.                             end;
  161.                 end;
  162.  
  163.            Temp[StrLength + 1] := #32;
  164.            GotoXY(X, Y);
  165.            Write(Temp);
  166.  
  167.            TextColor(12);
  168.            GotoXY(79, 25);
  169.            If InsFlag = True then Write('I') else Write(' ');
  170.               {Note:  Take out above 3 lines to not put an insert
  171.                status 'I' at the bottom of the screen             }
  172.  
  173.            TextColor(FC);
  174.            TextBackground(BC);
  175.            GotoXY(X + Location - 1, Y);
  176.            If QuitFlag <> True then Ch := ReadKey;
  177.  
  178.      until QuitFlag = True;
  179.  
  180.      Temp[0] := Chr(StrLength);
  181. end;
  182.  
  183. {--------------------------------------------------------------------------}
  184.  
  185. begin
  186. end.
  187.